import {createReducer} from '../utils';
import { LOGIN,
         ACTIVITY_INFO_CHANGE,
         SET_MY_ACTIVITY_LIST 
        } from '../constants';

const initialState = {
    userInfo: {
        phone:'',
        endTime:'',
    },
    info:{
        id:0,
        template:'bule',
        effects:'none',
        m1Title:'火热活动进行中',
        m2Title:'产品描述',
        m2Content:'',
        m3Title:'活动规则',
        m3Content:'',
        m4Title:'领奖信息',
        m4Content:'领奖时间： 领奖电话：',
        m5Title:'机构介绍',
        m5Content:'',
        m6Title:'咨询电话',
        m7Content:'',
        formName:'',
        formPhone:'',
        formDiy1:'',
        formDiy2:'',
        formDiy3:'',
        formDiyCheck:[false,false,false], //表单是否必填
        startTime:'',
        endTime:'',
        title:'欢迎参加在线报名活动',
        number:'100', //最多人数
        Cost:0, //报名费用
        Deposit:0, //报名订金
    },
    myActivityList:[],  //我的活动列表
};

export default createReducer(initialState, {
    [LOGIN['SUCCESS']]: (state, payload) => {
        let userInfo = Object.assign({}, state.userInfo, {
            'phone': payload.phone,
            'endTime':payload.end_time
        })
        return Object.assign({}, state, {
            'userInfo': userInfo
        });
    },
    [ACTIVITY_INFO_CHANGE]: (state, payload) => {
        let info = Object.assign({},state.info)
        const {type,e } = payload;
        if(type == 'startTime' || type == 'endTime' || type == 'template' || type == 'effects' || type == 'id'){
            info[type] = e;
        }else if(type == 'formCheck'){
            info.formDiyCheck[e.target.value] = e.target.checked;
        }else if(type == 'all'){
            info = e;
        }else{
            info[type] = e.target.value;
        }

        
        return Object.assign({}, state, {
            info
        });
    },
    [SET_MY_ACTIVITY_LIST]:(state, payload) => {
        return Object.assign({}, state, {
            'myActivityList': payload
        });
    },
});
